<template>
  <div class="home">
    <el-container>
      <el-header>
        <el-row>
          <el-col :span="2"><img src="@/assets/1.png" alt="" /></el-col>
          <el-col :span="20">
            <h2>后台管理系统</h2>
          </el-col>
          <el-col :span="2"
            ><el-button type="info" @click="backLogin"
              >退出登录</el-button
            ></el-col
          >
        </el-row>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '64px' : '200px'">
          <div style="height: 30px" @click="isCollapse = !isCollapse">|||</div>
          <el-menu
            :default-active="$route.name"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="blue"
            :collapse="isCollapse"
            :router="true"
            :unique-opened="true"
          >
            <el-submenu
              v-for="(item, index) in menus"
              :key="index"
              :index="item.path + ''"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group v-for="(item1, i) in item.children" :key="i">
                <el-menu-item :index="item1.path">{{
                  item1.authName
                }}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: '',
  components: {},
  data() {
    return {
      menus: [],
      isCollapse: false
    }
  },
  created() {
    this.getMenus()
  },
  mounted() {},
  methods: {
    backLogin() {
      sessionStorage.removeItem('token')
      this.$router.replace('/login')
    },
    async getMenus() {
      const res = await this.$QHL.Menusapi()
      console.log(res)
      this.menus = res
    }
  }
}
</script>
<style scoped lang="scss">
.home {
  height: 100%;

  .el-header {
    overflow: hidden;
    background-color: #373d41;
    color: #333;
    text-align: center;
    line-height: 60px;
    h2 {
      color: #fff;
      line-height: 20px;
      float: left;
    }
  }

  .el-aside {
    height: 100%;
    background-color: #333744;
    color: #fff;
    border: none;
    div {
      line-height: 30px;
      text-align: center;
    }
  }

  .el-main {
    background-color: #e9eef3;
    color: #333;
  }

  .el-container {
    margin-bottom: 40px;
    height: 100%;
  }
}
</style>
